package com.ys.controller.web.business;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bo.vo.W;
import com.ys.config.MenuId;
import com.ys.entity.business.TpAmazonSeller;
import com.ys.service.sys.CommonApiService;

@Controller
@RequestMapping("/web/business/tpAmazonSeller")
public class WebTpAmazonSellerController {

	@Autowired
	private CommonApiService<TpAmazonSeller> commonApiService;
	
	/*
	 * 新增
	 */
	@RequiresPermissions("tpAmazonSeller:add")
	@GetMapping("/toAdd")
	public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response){

		try {
			return commonApiService.toAdd(model, new TpAmazonSeller().setStatus(1), MenuId.TP_AmazonSeller, null, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}

	/*
	 * 修改
	 */
	@RequiresPermissions("tpAmazonSeller:edit")
	@GetMapping("/toEdit")
	public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id){
		
		Map<String, Object> extraParam = new TpAmazonSeller().setId(id)
				.addLeftJoin("TP_AmazonRegion B ON B.Code = A.RegionCode")
				.addField("B.Name regionName")
				
				.addLeftJoin("TB_Platform B1 ON B1.Code = B.PlatformCode")
				.addField("B1.Code platformCode")
				.addField("B1.Name platformName")
				
				.clearFieldsSource()
				.queryFirstMap();

		try {
			return commonApiService.toEdit(model, id, new TpAmazonSeller(), MenuId.TP_AmazonSeller, extraParam, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}
	
	/*
	 * 详情页
	 */
	@RequiresPermissions("tpAmazonSeller:view")
	@GetMapping("/toDetail")
	public String toDetail(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id){
		
		Map<String, Object> extraParam = new TpAmazonSeller().setId(id)
				.addLeftJoin("TP_AmazonRegion B ON B.Code = A.RegionCode")
				.addField("B.Name regionName")
				
				.addLeftJoin("TB_Platform B1 ON B1.Code = B.PlatformCode")
				.addField("B1.Code platformCode")
				.addField("B1.Name platformName")
				
				.clearFieldsSource()
				.queryFirstMap();

		try {
			return commonApiService.toDetail(model, id, new TpAmazonSeller(), MenuId.TP_AmazonSeller, extraParam, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}
}
